package org.jeecg.modules.wangyue.controller.sys;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.wangyue.constant.DelFlagConstant;
import org.jeecg.modules.wangyue.entity.Rakeback;
import org.jeecg.modules.wangyue.service.IRakebackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
* @Description: 返佣配置管理
* @Author: jeecg-boot
* @Date:   2023-07-31
* @Version: V1.0
*/
@Slf4j
@Api(tags="返佣配置管理")
@RestController
@RequestMapping("/wangyue/sys/rakeback")
public class RakebackManageController extends JeecgController<Rakeback, IRakebackService> {
   @Autowired
   private IRakebackService rakebackService;

   /**
    * 返佣配置管理-配置查询
    *
    * @return
    */
   @AutoLog(value = "返佣配置管理-配置查询")
   @ApiOperation(value="返佣配置管理-配置查询", notes="返佣配置管理-配置查询")
   @GetMapping(value = "/findRakebackAll")
   public Result<?> findRakebackAll() {
       QueryWrapper<Rakeback> queryWrapper = new QueryWrapper<>();
       queryWrapper.eq("del_flag", DelFlagConstant.normal);
       return Result.OK(rakebackService.list(queryWrapper));
   }

   /**
    * 返佣配置管理-保存
    *
    * @param rakebackArrMap
    * @return
    */
   @AutoLog(value = "返佣配置管理-保存")
   @ApiOperation(value="返佣配置管理-保存", notes="返佣配置管理-保存")
   @PostMapping(value = "/save")
   public Result<?> save(@RequestBody Map<String, Object> rakebackArrMap) {
       String rakebackArrStr = JSONObject.toJSONString(rakebackArrMap.get("rakebackArr"));
       List<Rakeback> rakebackList = JSONObject.parseArray(rakebackArrStr, Rakeback.class);
       rakebackService.saveOrUpdateBatch(rakebackList);
       return Result.OK("保存成功！");
   }


}
